<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="1. AOP两种实现方式：   ① JDK  Proxy代理类和自定义类实现InvocationHandler的invoke,一起用,调用处理;使用JDK的话必须要实现接口;优势： 通过反射创建对象 创建销量高 ②  cglib的asm搞字节码的class来搞这个切面编程的; 是基于子类，是基于继承;没有接口的时候，只能用这个;    优势： 执行效率高，但是创建不高 Spring默认用的是JDK">
<meta property="og:type" content="article">
<meta property="og:title" content="随笔">
<meta property="og:url" content="http://smallkk.gitee.io/2018/05/27/随笔/index.html">
<meta property="og:site_name" content="Hi , 小坤坤">
<meta property="og:description" content="1. AOP两种实现方式：   ① JDK  Proxy代理类和自定义类实现InvocationHandler的invoke,一起用,调用处理;使用JDK的话必须要实现接口;优势： 通过反射创建对象 创建销量高 ②  cglib的asm搞字节码的class来搞这个切面编程的; 是基于子类，是基于继承;没有接口的时候，只能用这个;    优势： 执行效率高，但是创建不高 Spring默认用的是JDK">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://s3.didiyunapi.com/sxk/pic/spring/ioc.jpg">
<meta property="og:image" content="https://s3.didiyunapi.com/sxk/pic/spring/ioc2.jpg">
<meta property="og:image" content="https://s3.didiyunapi.com/sxk/pic/spring/spring.jpg">
<meta property="og:image" content="https://s3.didiyunapi.com/sxk/pic/io/io.jpg">
<meta property="og:updated_time" content="2018-05-26T17:11:01.589Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="随笔">
<meta name="twitter:description" content="1. AOP两种实现方式：   ① JDK  Proxy代理类和自定义类实现InvocationHandler的invoke,一起用,调用处理;使用JDK的话必须要实现接口;优势： 通过反射创建对象 创建销量高 ②  cglib的asm搞字节码的class来搞这个切面编程的; 是基于子类，是基于继承;没有接口的时候，只能用这个;    优势： 执行效率高，但是创建不高 Spring默认用的是JDK">
<meta name="twitter:image" content="https://s3.didiyunapi.com/sxk/pic/spring/ioc.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://smallkk.gitee.io/2018/05/27/随笔/"/>





  <title>随笔 | Hi , 小坤坤</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Hi , 小坤坤</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallkk.gitee.io/2018/05/27/随笔/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="S-Name Small·kk">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hi , 小坤坤">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">随笔</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-27T01:11:23+08:00">
                2018-05-27
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>1. AOP</strong><br>两种实现方式： </p>
<ul>
<li>① JDK  Proxy代理类和自定义类实现InvocationHandler的<code>invoke</code>,一起用,调用处理;使用JDK的话必须要实现接口;优势： 通过反射创建对象 创建销量高</li>
<li>②  cglib的asm搞字节码的class来搞这个切面编程的; 是基于子类，是基于继承;没有接口的时候，只能用这个;    优势： 执行效率高，但是创建不高</li>
<li>Spring默认用的是JDK方式,面向接口编程,动态代理,拦截有接口的方法</li>
<li>使用场景： 事务,同步,错误处理,日志等</li>
</ul>
<p><strong>1.5 IOC</strong></p>
<ul>
<li>IOC容器其实就是一个大工厂</li>
<li>原理就是通过Java的反射技术来实现的！通过反射我们可以获取类的所有信息(成员变量、类名等等等)！</li>
<li>Spring4.x开始IOC容器装配Bean有4种方式：<ul>
<li>XML配置</li>
<li>注解</li>
<li>JavaConfig</li>
<li>基于Groovy DSL配置(这种很少见)</li>
</ul>
</li>
<li>依赖注入的方式有3种方式：<ul>
<li>属性注入–&gt;通过setter()方法注入</li>
<li>构造函数注入</li>
<li>工厂方法注入</li>
</ul>
</li>
<li>Bean的作用域：<ul>
<li>单例Singleton</li>
<li>多例prototype</li>
<li>与Web应用环境相关的Bean作用域(request,session)<br><img src="https://s3.didiyunapi.com/sxk/pic/spring/ioc.jpg" alt="image"></li>
</ul>
</li>
</ul>
<p><img src="https://s3.didiyunapi.com/sxk/pic/spring/ioc2.jpg" alt="image"></p>
<p><img src="https://s3.didiyunapi.com/sxk/pic/spring/spring.jpg" alt="image"></p>
<ul>
<li><strong>使用Spring框架的好处是什么</strong>？<ul>
<li><strong>轻量</strong>：Spring 是轻量的，基本的版本大约2MB。</li>
<li><strong>控制反转</strong>：Spring通过控制反转实现了松散耦合，对象们给出它们的依赖，而不是创建或查找依赖的对象们。</li>
<li><strong>面向切面的编程(AOP)</strong>：Spring支持面向切面的编程，并且把应用业务逻辑和系统服务分开。</li>
<li>容器：Spring 包含并管理应用中对象的生命周期和配置。</li>
<li>MVC框架：Spring的WEB框架是个精心设计的框架，是Web框架的一个很好的替代品。</li>
<li>事务管理：Spring 提供一个持续的事务管理接口，可以扩展到上至本地事务下至全局事务（JTA）。</li>
<li>异常处理：Spring 提供方便的API把具体技术相关的异常（比如由JDBC，Hibernate or JDO抛出的）转化为一致的unchecked 异常。</li>
</ul>
</li>
<li>IOC的优点是什么？<ul>
<li>最小的代价和最小的侵入性使松散耦合得以实现。IOC容器支持加载服务时的饿汉式初始化和懒加载。</li>
</ul>
</li>
</ul>
<ol start="2">
<li><p>随机数的边界：<br>Random random = new Random();<br>return String.valueOf(random.nextInt(10000)); 表示生成的是一个10000以内的4位数</p>
</li>
<li><p>字符串的截取： return StringUtils.substring(String.valueOf(random.nextInt()), 2, 6);</p>
</li>
<li><p>SpringBoot的3种启动方式：<br>①IDEA启动<br>②在项目目录下进入命令行输入   mvn spring-boot:run<br>③项目目录下进入命令行输入 mvn install (先将项目编译,会生成target目录)<br>cd target     java -jar 项目名.jar<br>5.SpringBoot的这三种启动方式可以同时启动但是，要设置不同的启动端口；</p>
</li>
<li><p>@Value(直接注入参数)  @Component(针对不能注入的情况其实是可以注入的)<br> @ConfigurationProperties(prefix=”xxx”) 是获取配置文件中的配置;     dev / prod 多环境配置</p>
</li>
<li><p>@Controller 处理http请求 @RequestMapping 配置url映射<br> @RestController Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Controller </p>
</li>
</ol>
<ol start="8">
<li><p>@PathVariable 获取url中的数据<br>eg: @re..ing(“/hello/{id}”) 方法中say(@PathVariable(“id”) Integer id)<br>传统的通过问号的方式传值：方法里面：say(@RequestParam(“id”) Integer myId) -&gt;  ?id=123<br>public String say(@RequestParam(value=”id”,required=false,defaultValue=”0”)Integer myId)<br>通过问号来传一个值，是否必传：否；默认值为“0” (此处不能为整型，只能为字符)</p>
</li>
<li><p>@RequestParam 获取请求参数的值</p>
</li>
<li><p>@GetMapping 组合注解      @GetMapping ==   @RequestMapping</p>
</li>
<li><p>JPA(JAVA Persistence API)定义了一系列对象持久化的标准，目前实现这一规范的产品还有                                 Hibernate、TopLink</p>
</li>
<li><p>SpringBoot建表规范：<br>JPA的配置：    </p>
</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">datasource:</span><br><span class="line">  driver-class-name: com.mysql.jdbc.Driver</span><br><span class="line">  url: jdbc:mysql://localhost/ooo</span><br><span class="line">  username: root</span><br><span class="line">  password: war3sxkcs</span><br><span class="line">jpa:</span><br><span class="line">  hibernate:</span><br><span class="line">    ddl-auto: create</span><br><span class="line">  show-sql: true</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">对象类：</span><br><span class="line">@Entity// 表示是实体</span><br><span class="line">    @Data</span><br><span class="line">public class Girl &#123;</span><br><span class="line">    @Id //表示这个是主键</span><br><span class="line">    @GeneratedValue// 表示是自动增长</span><br><span class="line">    private Integer id;</span><br><span class="line">    private String cupSize;</span><br><span class="line">    private Integer age;</span><br><span class="line">这个样子生成的SQL</span><br><span class="line">CREATE TABLE `girl` (</span><br><span class="line">  `id` int(11) NOT NULL AUTO_INCREMENT,</span><br><span class="line">  `age` int(11) DEFAULT NULL,</span><br><span class="line">  `cup_size` varchar(255) DEFAULT NULL,</span><br><span class="line">  PRIMARY KEY (`id`)</span><br><span class="line">  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</span><br></pre></td></tr></table></figure>
<p>注意：在JPA的配置中   ddl-auto: create 表示创建这个表如果表里面有值的话会将原来的值先删除；如果是ddl-auto: update的话，就不会删除里面的内容</p>
<ol start="13">
<li><p>Linux命令行下载文件：  wget  https://……</p>
</li>
<li><p>jsp中的PrintWriter会先于out打印出来;不管这两个在代码里写的顺序;打印出来都是printwriter先;但是如果想让这两个按照在代码里面写的顺序打印出来的话就要使用out.flush强制释放输出.</p>
</li>
<li><p>重定向： response.sendRedirect(location) 服务器重新请求到一个新的地方</p>
</li>
<li><p>请求重定向：response.sendRedirect:客户端行为，从本质上讲等同于两次请求，前一次的请求对象不会保存，地址栏的URL地址会改变。请求转发request.getRequestDispatcher().forward(req,resp)是一次请求，转发后请求对象会保存，地址栏的URL地址不会改变</p>
</li>
<li><p>Session生命周期： 活动: 某次会话当中通过超链接打开的新特免属于同一会话；只有当前会话页面没有全部关闭，重新打开新的浏览器窗口访问同一项目资源的时候属于同一次会话。除非本次会话的所有页面都关闭后再重新访问某个JSP或者Servlet将会创建新的会话。(注意：原有的会话还存在，只是这个旧的的session仍然存在于服务端，只不过再也没有客户端会携带它然后交于服务端校验)</p>
</li>
<li><p>StringUtils.isNotBlank :(“  “)false  引号里面有无数个空格， 也表示这个值为空<br>StringUtils.isNotEmpty:(“  “)  true  引号里面有空格，表示这是个实值，有字符</p>
</li>
<li><p>@RequestParam(value = “categoryId”, defaultValue = “0”) Integer categoryId<br>动态传递参数通过URL的 “?” 、GET的请求方式</p>
</li>
<li><p>ArrayList和LinkList各有所长,综合两者优点,就用HashMap</p>
</li>
<li></li>
</ol>
<ul>
<li>Thread.yield();表示执行到这一行的时候,让出当前的执行权;</li>
<li>启动thread.start()方法后并不是立即就执行,而是进入了一种可执行的状态,等待是否可以执行</li>
<li>thread.join();表示执行到这儿的时候,thread线程开始执行,执行完了后再执行其他的线程</li>
<li>Thread.interrupt();中断线程标志位,但是并不会被中止</li>
<li>wait();是线程等待,需要notify();方法来唤醒;(涉及到两个对象：new Waiter();new Notifiter() )</li>
</ul>
<p>22.自定义异常类里面用到的注解：</p>
<ul>
<li>@ResponseBody    转化为JSON</li>
<li>@ControllerAdvice  对Controller层进行拦截处理</li>
<li>@ExceptionHandler(Exception.class)  捕获到这个(Controller层)类的异常</li>
</ul>
<ol start="23">
<li></li>
</ol>
<ul>
<li>synchronised;同步代码块; 锁 可以是任何一个对象</li>
<li>synchronised static 静态方法锁是锁的整个类,所有的对象(上升到类级别)过来都会阻塞</li>
</ul>
<ol start="24">
<li>IO:文件的读写创建</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">public static void La() throws IOException &#123;</span><br><span class="line">        File file = new File(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;);</span><br><span class="line">        if (file.exists()) &#123;</span><br><span class="line">            System.out.println(&quot;文件已经存在&quot;);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            //新建并写入</span><br><span class="line">            file.createNewFile();</span><br><span class="line">            PrintWriter printWriter = new PrintWriter(file);</span><br><span class="line">            printWriter.print(&quot;现在输入了第一句话&quot;);</span><br><span class="line">            printWriter.println(399);</span><br><span class="line">            printWriter.print(&quot;这是最后一句话&quot;);</span><br><span class="line">            printWriter.close();</span><br><span class="line">        &#125;</span><br><span class="line">        if (file.exists()) &#123;</span><br><span class="line">            //读取</span><br><span class="line">            Scanner scanner = new Scanner(file);</span><br><span class="line">            while (scanner.hasNext()) &#123;</span><br><span class="line">                String print = scanner.nextLine();</span><br><span class="line">                System.out.println(print);</span><br><span class="line">            &#125;</span><br><span class="line">            scanner.close();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<ol start="25">
<li></li>
</ol>
<ul>
<li>字符流：中文英文;    字节流:二进制 </li>
<li>装饰模式 和 适配器模式</li>
</ul>
<p><img src="https://s3.didiyunapi.com/sxk/pic/io/io.jpg" alt="image"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">public PrintWriter(File file) throws FileNotFoundException &#123;</span><br><span class="line">    this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))),</span><br><span class="line">         false);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>字节流 读写:  (字节流既能操作字节又能操作字符)</li>
<li>直接复制读写不会出什么错</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">     InputStream in = new FileInputStream(new File(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;));</span><br><span class="line">     OutputStream out = new FileOutputStream(new File(&quot;C:\\Users\\song\\Desktop\\aaa\\b.txt&quot;));</span><br><span class="line">     int ch;</span><br><span class="line">     while ((ch = in.read()) != -1) &#123;</span><br><span class="line">         out.write(ch);</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>但是要输输出就不得行了,如果是中文的话一个字符是两个即以上的字节,所以要用数组来装并且还需要源文件是UTF-8的才能处理;</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">       InputStream in = new FileInputStream(new File(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;));</span><br><span class="line">       OutputStream out = new FileOutputStream(new File(&quot;C:\\Users\\song\\Desktop\\aaa\\b.txt&quot;));</span><br><span class="line">       int ch;</span><br><span class="line">       String str = &quot;&quot;;</span><br><span class="line">       byte[] buff = new byte[512];</span><br><span class="line">       while ((ch = in.read(buff)) != -1) &#123;</span><br><span class="line">           //ch表示是读到第几个了;read(buff)表示将读到的东西装进buff数组里面去</span><br><span class="line">           str = str + new String(buff, 0, ch);</span><br><span class="line">           //将数组中的字符串拼接</span><br><span class="line">           System.out.print(str);</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>上面是自定义了一个缓存区但是容量大小不稳定;所以就有了一个带缓冲区的读：即Buffer…</p>
</li>
<li><p>字符流：  就可以将中文字符完全正确的输出</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">     Reader reader = new FileReader(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;);</span><br><span class="line">     int n;</span><br><span class="line">     while ((n = reader.read()) != -1) &#123;</span><br><span class="line">         System.out.print((char) n);</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>读取出来并写入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">    Reader reader = new FileReader(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;);</span><br><span class="line">    Writer writer = new FileWriter(&quot;C:\\Users\\song\\Desktop\\aaa\\b.txt&quot;);</span><br><span class="line">    int n;</span><br><span class="line">    while ((n = reader.read()) != -1) &#123;</span><br><span class="line">        writer.write((char) n);</span><br><span class="line">        System.out.print((char) n);</span><br><span class="line">    &#125;</span><br><span class="line">    writer.close();</span><br><span class="line">    //要注意一定要关流</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>转换流, 将字节流转换成字符流</p>
</li>
<li><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Reader inputStreamReader = new InputStreamReader(new FileInputStream(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;), &quot;utf-8&quot;);</span><br><span class="line">       inputStreamReader.read();</span><br></pre></td></tr></table></figure>
</li>
<li><p>带缓冲区的读可以读取一整行！</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">        Reader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;), &quot;utf-8&quot;));</span><br><span class="line">        String str = &quot;&quot;;</span><br><span class="line">        String line;</span><br><span class="line">        while ((line = ((BufferedReader) bufferedReader).readLine()) != null) &#123;</span><br><span class="line">        //带缓冲的读可以读取一整一行！</span><br><span class="line">            str = str + line+&quot;\n&quot;;</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.print(str);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>带缓冲区的写入,也与上面一致;只是不会包括换行,所以要写入换行的话要用方法：<code>writer.newLine();</code></li>
<li>DataInputStream (可以获取从客户端过来的东西,可以双精度)</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws Exception &#123;</span><br><span class="line">       try (</span><br><span class="line">               DataInputStream inputStream = new DataInputStream(new FileInputStream(&quot;C:\\Users\\song\\Desktop\\aaa\\a.txt&quot;));</span><br><span class="line">               DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(&quot;C:\\Users\\song\\Desktop\\aaa\\b.txt&quot;));</span><br><span class="line">       ) &#123;</span><br><span class="line">           outputStream.writeUTF(&quot;LaLaLa&quot;);</span><br><span class="line">           outputStream.writeDouble(123.456);</span><br><span class="line">           System.out.println(inputStream.readUTF());</span><br><span class="line">           System.out.println(inputStream.readDouble());</span><br><span class="line">           inputStream.close();</span><br><span class="line">           outputStream.close();</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/05/01/First-Bolg/" rel="next" title="First Bolg">
                <i class="fa fa-chevron-left"></i> First Bolg
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/05/28/http/" rel="prev" title="HTTP">
                HTTP <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">S-Name Small·kk</p>
              <p class="site-description motion-element" itemprop="description">开源 | Java | 个人笔记 | 我的博客</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">S-Name Small·kk</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
